﻿using System;
using System.Collections.Generic;
using System.IO;

namespace ServerFramework.Script
{
    public static class ScriptUtil
    {

        public static string GetScriptPath(string scriptName)
        {
            string path = "Script/" + scriptName + "/";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return path;
        }

        public static List<string> GetScriptFiles(string scriptName)
        {
            string path = GetScriptPath(scriptName);
            string[] files = Directory.GetFiles(path);
            List<string> paths = new List<string>();
            foreach(var  f in files)
            {
                if(FilterFile(scriptName,f))
                {
                    FileInfo file = new FileInfo(f);
                    paths.Add(file.FullName);
                }
            }
            return paths;
        }

        private static bool FilterFile(string scriptName,string FullName)
        {
            string tmp = FullName.ToLower();
            if(tmp.EndsWith(scriptName.ToLower()))
            {
                return true;
            }
            return false;
        }
    }
}
